<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="member/header::head('注册')">
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <form class="ajaxforms" method="post" action="/member/reg">
                    <div class="form-group">
                        <label for="account">账号</label>
                        <input type="text" class="form-control"  name="account" id="account" placeholder="账号">
                    </div>
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" name="password" class="form-control" id="password" placeholder="密码">
                    </div>
                    <input type="submit" class="form-control btn-primary" value="注册" />
                </form>
            </div>
        </div>
    </div>

    <div th:include="member/footer"></div>
    <script type="text/javascript">
        $(function () {
            var form = $("form.ajaxforms");
            var formloading = false;
            form.validate({
                showErrors : function(errorMap, errorArr) {
                    try {
                        $(errorArr[0].element).focus();
                        layer.msg(errorArr[0].message);
                    } catch (err) {
                    }
                },
                rules : {
                    'account' : {
                        required : true
                    },
                    'password' : {
                        required : true,
                    }
                },
                //验证未通过提示消息
                messages : {
                    'account' : {
                        required : '请输入账号'
                    },
                    'password' : {
                        required : '请输入密码'
                    },
                },
                submitHandler : function(forms) {
                    if (formloading) return;
                    $(forms).ajaxSubmit({
                        url : form.attr('action'),
                        dataType : 'json',
                        beforeSubmit : function(arr, $form, options) {
                            formloading = true;
                        },
                        success : function(data, statusText, xhr, $form) {
                            formloading = false;
                            if (data.status == 1) {
                                window.location.href = '/member/login';
                            } else {
                                layer.msg(data.msg);
                            }
                        }
                    });
                }
            })
        })(jQuery);
    </script>
</body>
</html>